package com.gis.dto;

import com.gis.enums.QualityReportEnum;
import lombok.Data;

@Data
public class SedimentReportDTO {
    private Integer stationId;
    private String name;
    private Float latitude;
    private Float longitude;
    //汞
    private Float mercury;
    //铅
    private Float lead;
    //镉
    private Float cadmium;
    //锌
    private Float zinc;
    //砷
    private Float arsenic;
    //铜
    private Float copper;
    //铬
    private Float chromium;
    //石油类
    private Float petroleumClass;
    // 有机碳
    private Float oc;
    // 硫化物
    private Float sulfide;


    // 各指标分类
    private int classMercury;
    private int classLead;
    private int classCadmium;
    private int classZinc;
    private int classArsenic;
    private int classCopper;
    private int classChromium;
    private int classPetroleumClass;
    private int classOc;
    private int classSulfide;


    public void setClassMercury() {
        this.classMercury = classifySedimentQuality(0,this.mercury).getCode();
    }

    public void setClassLead() {
        this.classLead = classifySedimentQuality(1,this.lead).getCode();
    }

    public void setClassCadmium() {
        this.classCadmium = classifySedimentQuality(2,this.cadmium).getCode();
    }

    public void setClassZinc() {
        this.classZinc = classifySedimentQuality(3,this.zinc).getCode();
    }

    public void setClassArsenic() {
        this.classArsenic = classifySedimentQuality(4,this.arsenic).getCode();
    }

    public void setClassCopper() {
        this.classCopper = classifySedimentQuality(5,this.copper).getCode();
    }

    public void setClassChromium() {
        this.classChromium = classifySedimentQuality(6,this.chromium).getCode();
    }

    public void setClassPetroleumClass() {
        this.classPetroleumClass = classifySedimentQuality(7,this.petroleumClass).getCode();
    }

    public void setClassOc() {
        this.classOc = classifySedimentQuality(8,this.oc).getCode();
    }

    public void setClassSulfide() {
        this.classSulfide = classifySedimentQuality(9,this.sulfide).getCode();
    }

    /**
     * 沉积物参数分类
     */
    private final static double[][] sedimentStandards = {
            {0.20, 1.00},  // 汞
            {60.0, 250.0},  // 铅
            {0.50, 5.00},  // 镉
            {150.0, 600.0},  // 锌
            {20.0, 93.0},  // 砷
            {35.0, 200.0},  // 铜
            {80.0, 270.0},  // 铬
            {500.0, 1500.0},  // 石油类
            {2.0, 4.0},  // 有机碳
            {300.0, 600.0}  // 硫化物
    };
    private QualityReportEnum classifySedimentQuality(int index, Float param) {
        if (param < 0) return QualityReportEnum.FIRST_CLASS;
        if (param <= sedimentStandards[index][0]) return QualityReportEnum.FIRST_CLASS;
        if (param <= sedimentStandards[index][1]) return QualityReportEnum.SECOND_CLASS;
        return QualityReportEnum.THIRD_CLASS;
    }

    public int getComprehensiveClass() {
        boolean isOcAndSulfideNot3 = classOc!=3 && classSulfide!=3;
        boolean areAllOther1 = classMercury == 1 && classLead == 1 && classCadmium == 1 && classZinc == 1 &&
                classArsenic == 1 && classCopper == 1 && classChromium == 1 && classPetroleumClass == 1;
        boolean areAllOther2 = classMercury == 2 && classLead == 2 && classCadmium == 2 && classZinc == 2 &&
                classArsenic == 2 && classCopper == 2 && classChromium == 2 && classPetroleumClass == 2;

        if (isOcAndSulfideNot3 && areAllOther1) {
            return 1;
        } else if (isOcAndSulfideNot3 && areAllOther2) {
            return 2;
        } else {
            return 3;
        }
    }



}
